<template>
  <van-row class="car_circle_wrap">
    <!-- <div class="p-c-data">
      <p class="p-c-title">优秀的父母都是这么做的</p>
      <p class="c-f-true">{{submit_count}}+父母和您一起关注孩子的成长</p>
    </div>
    <div ref="pride_tab_fixed" class="task-area-tab" :class="isFixed ? 'is_fixed' : ''">
      <div class="task-tab-item" :class="tabIndex == index ? 'tab-active-color' : ''"  @click="getActive(index)" v-for="(item, index) in navList" :key="index">
        {{ item.value }}
      </div>
    </div> -->
    <!-- finished\loading -->
    <van-list
      v-model="loading"
      :finished="finished"
      :immediate-check="false"
      :offset="10"
      @load="onLoad"
    >
      <div :data-id="list.length" class="item_wrap">
        <div v-for="(item, index) in list" :key="index" class="item_task">
          <van-col :span="24" class="task_top">
            <van-col :span="4">
              <van-image :src="handle_pic(item.avatar)" round cover class="img_item" />
            </van-col>
            <van-col :span="20">
              <van-col :span="24" class="vertical user_name">
                <span>{{ item.username }}</span>
              </van-col>
              <van-col :span="24" class="sign-total">{{ item.create_time }}</van-col>
            </van-col>
          </van-col>
          <div class="task_content">
            <van-col :span="24" class="brocade-content">
              <span v-html="item.item_content" />
            </van-col>
            <image-view :list="item.pic_list" />
          </div>
          <div span="24" class="card_bottom">
            <div span="24" class="introduce_right">
              <i class="iconfont icon-liulan liulan_sty" /><span>{{
                item.view_num
              }}</span>
              <i
                :style="{ color: item.is_zan ? '#ee0a24' : '' }"
                class="iconfont icon-dianzan dianzan_sty"
                @click="zanAction(item, index)"
              /><span>{{ item.zan_num }}</span>
            </div>
          </div>
        </div>
      </div>
    </van-list>
    <div v-if="list.length <= 0" class="no-data">
      <img :src="require('@/assets/images/empty.jpeg')" alt="">
      <div class="no-title">哎呦~还没有呢, 先去看看其他吧</div>
    </div>
    <div class="publish_fixed" @click="publicsCirle">
      <van-icon name="edit" class="publish_icon"/>
      <span class="publish_text">发布</span>
    </div>
    <div class="publish_fixed luck_fixed" @click="luckDraw">
      <van-icon name="point-gift-o" class="gift_icon" />
    </div>
  </van-row>
</template>

<script>
import imageView from '@/components/ImageView'
import api from '@/api/car'
export default {
  components: { imageView },
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      params: {
        page_num: 1,
        page_size: 10,
        type: 2
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    publicsCirle() {
      this.$router.push({ name: 'PublishCircle' })
    },
    luckDraw() {
      this.$router.push({ name: 'LickDrawPage' })
    },
    zanAction(item, index) {
      if (item.is_zan) return
      const params = { article_id: item.article_id }
      api.zanAction(params).then((res) => {
        if (parseInt(res.code) === 200) {
          this.list[index].zan_num += 1
          this.list[index].is_zan = true
        } else {
          this.$toast.fail(res.msg)
        }
      })
    },
    onLoad() {
      this.params.page_num++
      this.getList()
    },
    getList() {
      this.$toast.loading({
        forbidClick: true,
        mask: false,
        duration: 0,
        message: '加载中...'
      })
      api.articleList(this.params)
        .then((res) => {
          this.$toast.clear()
          if (parseInt(res.code) === 200) {
            res.result.forEach(el => {
              const pics = JSON.parse(el.detail_pic)
              el.pic_list = Array.from(pics, (item) => (this.handle_pic(item)))
            })
            this.list = [...this.list, ...res.result]
            if (this.params.page_size > res.result.length) {
              this.finished = true
            } else {
              this.finished = false
            }
          }
        })
        .catch(() => { this.$toast.clear() })
    }
  }
}
</script>

<style lang="less" scoped>
.car_circle_wrap {
  .item_wrap{
    padding: 0 16px 80px;
    .item_task {
      box-shadow: 0px 4px 8px 4px rgba(240, 240, 240, 1);
      border-radius: 10px;
      margin-top: 10px;
      padding-bottom: 5px;
      .task_top {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        padding: 15px 0 0 14px;
        .img_item {
          width: 42px;
          height: 41px;
          margin-right: 10px;
        }
        .user_name {
          font-weight: 500;
          color: #333333;
          span {
            display: inline-block;
            max-width: 160px;
            overflow:hidden;
            text-overflow:ellipsis;
            white-space:nowrap;
          }
        }
        .sign-total {
          font-size: 12px;
          color: #999999;
          margin-top: 5px;
          span {
            color: #999999;
          }
        }
      }
      .task_content {
        padding: 0 14px;
        margin-top: 10px;
        overflow: hidden;
        .brocade-content {
          margin: 10px 0 10px;
          font-family: PingFangSC-Regular;
          font-weight: 400;
          color: #333333;
          line-height: 20px;
          word-break: break-all;
        }
        span {
          font-weight: 400;
          color: #333333;
          line-height: 20px;
        }
      }
      .operation {
        display: flex;
        justify-content: flex-end;
        font-size: 12px;
        padding: 10px 16px;
        span {
          margin-left: 5px;
        }
        .item {
          margin-left: 10px;
        }
        .item.active {
          color: #E60039;
        }
      }
      .task_bottom {
        padding: 0 14px;
        margin-top: 12.5px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        .icon_s {
          font-size: 14px;
          font-weight: 400;
          color: #666666;
          margin-right: 5px;
        }
        .number_s {
          font-size: 10px;
          font-weight: 400;
          color: #666666;
        }
      }
      .card_bottom {
        display: flex;
        align-items: center;
        justify-content: space-between;
        background-color: #fff;
        border-radius: 0 0 12.5px 12.5px;
        .introduce_right {
          display: flex;
          align-items: center;
          justify-content: flex-end;
          padding-right: 10px;
          width: 100%;
          line-height: 20px;
          .liulan_sty {
            color: #999;
            font-size: 10px;
            margin-right: 5px;
          }
          .dianzan_sty {
            color: #999;
            font-size: 12px;
            margin: 0 5px 0 10px;
          }
          span {
            color: #999;
            font-size: 12px;
          }
        }
      }
    }
  }
  .no-data {
    width: 80%;
    margin: 0 auto;
    height: auto;
    img {
      width: 40%;
      margin: 30px auto 0;
      height: 100%;
      display: block;
    }
    .no-title {
      width: 100%;
      font-size: 14px;
      color: #999999;
      text-align: center;
    }
  }
  .publish_fixed{
    position: fixed;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    bottom: 100px;
    right: 10px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: orange;
    color: #000;
    .publish_icon{
      font-size: 16px;
    }
    .gift_icon{
      font-size: 24px;
      color: #fff;
    }
    .publish_text{
      font-size: 10px;
      margin-top: 4px;
    }
  }
  .luck_fixed{
    bottom: 160px;
  }
}
</style>
